<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../node_modules/vue/dist/vue.global.js"></script>
</head>
<body>
    <div id="app">
        <my-blog v-for="blog in showblogs" 
        :key="blog.id" :title="blog.content"
        :id="blog.id"
        @close="handleClick"></my-blog>
    </div>
    <script>
        const app = Vue.createApp({
            data(){
                return {
                    blogs : [
                        {id : 1, content:'内容1',isShow : true},
                        {id : 2, content:'内容2',isShow : true},
                        {id : 3, content:'内容3',isShow : true},
                ]
                }
            },
            methods :{
                handleClick(value){
                    return this.blogs.find(item => item.id === value).isShow = false
                },
            },
            computed : {
                showblogs(){
                    return this.blogs.filter(item => item.isShow)
                }
            },
            components : {
                MyBlog : {
                    props : ['title','id'],
                    template : `
                        <div style="  width: 500px ; border: 1px solid black ">
                            <h1>{{ title }}</h1>
                            <button @click= "handleClose">关闭</button>
                        </div>

                    `,
                    methods : {
                        handleClose(){
                            return this.$emit('close', this.id)
                    }
                }
            }
            }
        }).mount('#app')
    </script>
</body>
</html>